<template>
  <div>
    <el-form ref="form" :model="form" :rules="rules" label-width="100px">
      <el-form-item label="产品名称" prop="name">
        <el-input v-model="form.name" placeholder="请输入商品名称" />
      </el-form-item>
      <el-form-item label="品牌" prop="price">
        <el-input v-model="form.price" placeholder="请输入商品价格" />
      </el-form-item>
      <el-form-item label="产品类目" prop="stock">
        <el-input v-model="form.stock" placeholder="请输入商品库存" />
      </el-form-item>
      <el-form-item label="商品描述" prop="description">
        <el-input v-model="form.description" placeholder="请输入商品描述" />
      </el-form-item>
      <el-form-item label="商品图片" prop="image">
        <el-input v-model="form.image" placeholder="请输入商品图片" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handleSubmit">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: 'ProductDetails',
  props: {
    product: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  data() {
    return {
      form: {
        name: this.product.name,
        price: this.product.price,
        stock: this.product.stock,
        description: this.product.description,
        image: this.product.image
      },
      rules: {
        name: [
          { required: true, message: '请输入商品名称', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    handleSubmit() {
      this.$refs.form.validate(valid => {
        if (valid) {
          console.log('submit!')
        } else {
          console.log('error submit!!')
          return false
        }
      })
    }

  }
}
</script>

<style scoped>

</style>
